# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'daywidget.ui'
#
# Created: Mon May 14 14:18:20 2012
#      by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from pl.edu.budgetanalizer.model.Note import Note
import NewNote
import NoteWidget
import pyodbc


try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_dayWidget(QtGui.QWidget):
    
    lastNoteY = 10;
    listOfNotes = []
    currentIdNote = 0
    currentNote = 0
    currentTopic = ""
    

        
    def newNote(self):
        '''
        Naklada nowego widgeta na centrum aplikacji
        '''
        self.newNoteWidget = NewNote.Ui_dayWidgetNewNote(self)
        self.newNoteWidget.setupUi(self.newNoteWidget,self.date,[],[],self.databaseDir,"",self.login)
        self.newNoteWidget.setGeometry(QtCore.QRect(0, 0, 461, 511))
        self.newNoteWidget.setAutoFillBackground(True)
        self.newNoteWidget.show()
        
    def nextNote(self):
        if len(self.listOfNotes) <> 0:
            self.currentNote += 1
            if self.currentNote > len(self.listOfNotes):
                self.currentNote = 1
            self.notesLabel.setText(QtGui.QApplication.translate("dayWidget", str(self.currentNote) + "/" + str(len(self.listOfNotes)), None, QtGui.QApplication.UnicodeUTF8))
            self.currentTopic = self.listOfNotes[self.currentNote-1].topic
            self.setNoteWidget(self.listOfNotes[self.currentNote-1].id_note)
       
    
    def previousNote(self):
        if len(self.listOfNotes) <> 0:
            self.currentNote -= 1
            if self.currentNote < 1:
                self.currentNote = len(self.listOfNotes)
            self.notesLabel.setText(QtGui.QApplication.translate("dayWidget", str(self.currentNote) + "/" + str(len(self.listOfNotes)), None, QtGui.QApplication.UnicodeUTF8))
            self.currentTopic = self.listOfNotes[self.currentNote-1].topic
            self.setNoteWidget(self.listOfNotes[self.currentNote-1].id_note)
        
    def getAllNoteOnDay(self):
        '''
        pobiera wszystkie notatki z danego dnia
        '''
        self.listOfNotes = []
        conn = pyodbc.connect(self.databaseDir)
        cur = conn.cursor()
        day = self.date.day()
        month = self.date.month()
        year = self.date.year()
        date = str(year)+"-"+str(month)+"-"+str(day)
        cur.execute("exec getAllNotes ?",date)
        rows = cur.fetchall()
        for row in rows:
            note = Note(row[0],row[1],date,row[2])     #note_id,topic,data, user
            self.listOfNotes.append(note)
    
        conn.close()
        if len(self.listOfNotes) <> 0:
            self.currentIdNote = self.listOfNotes[0].id_note
            self.currentTopic = self.listOfNotes[0].topic
            self.currentNote = 1
        else:
            self.currentIdNote = 0
    
    def setNoteWidget(self,id_note):
        print id_note
        self.newNoteWidget = NoteWidget.Ui_NoteWidget(self)
        self.newNoteWidget.setupUi(self.newNoteWidget,self.databaseDir,id_note,self.date)
        self.newNoteWidget.setGeometry(QtCore.QRect(0, 0, 461, 450))
        self.newNoteWidget.setAutoFillBackground(True)
        self.newNoteWidget.show()
        
     
        
    
    
    
    '''
        wygenerowane gui
    '''
    def setupUi(self, dayWidget,date,databaseDir,login):
        self.login= login
        self.databaseDir = databaseDir
        self.date = date
        dayWidget.setObjectName(_fromUtf8("dayWidget"))
        dayWidget.resize(479, 492)

        self.horizontalLayoutWidget = QtGui.QWidget(dayWidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(20, 10, 281, 41))
        self.horizontalLayoutWidget.setObjectName(_fromUtf8("horizontalLayoutWidget"))
        self.dataHorizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
        self.dataHorizontalLayout.setMargin(0)
        self.dataHorizontalLayout.setObjectName(_fromUtf8("dataHorizontalLayout"))
        self.dataTextLabel = QtGui.QLabel(self.horizontalLayoutWidget)
        self.dataTextLabel.setObjectName(_fromUtf8("dataTextLabel"))
        self.dataHorizontalLayout.addWidget(self.dataTextLabel)
        self.dataLabel = QtGui.QLabel(self.horizontalLayoutWidget)
        self.dataLabel.setObjectName(_fromUtf8("dataLabel"))
        self.dataHorizontalLayout.addWidget(self.dataLabel)
        
        
        self.centralArea = QtGui.QWidget(dayWidget)
        self.centralArea.setObjectName(_fromUtf8("centralArea"))
        self.centralArea.setGeometry(QtCore.QRect(20, 60, 431, 411))

        

        '''
        Pobiera wszystkie notatki z danego dnia
        '''
        self.getAllNoteOnDay()
        if len(self.listOfNotes) <> 0:
            self.setNoteWidget(self.currentIdNote)
        
        #przycisk dodawania nowej notatki
        self.horizontalLayoutWidget_4 = QtGui.QWidget(dayWidget)
        self.horizontalLayoutWidget_4.setGeometry(QtCore.QRect(20, 480, 241, 31))
        self.horizontalLayoutWidget_4.setObjectName(_fromUtf8("horizontalLayoutWidget_4"))
        self.addNoteHorizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget_4)
        self.addNoteHorizontalLayout.setMargin(2)
        self.addNoteHorizontalLayout.setObjectName(_fromUtf8("addNoteHorizontalLayout"))
        self.addNoteButton = QtGui.QPushButton(self.horizontalLayoutWidget_4)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.addNoteButton.sizePolicy().hasHeightForWidth())
        self.addNoteButton.setSizePolicy(sizePolicy)
        self.addNoteButton.setMinimumSize(QtCore.QSize(15, 0))
        self.addNoteButton.setMaximumSize(QtCore.QSize(27, 23))
        self.addNoteButton.setObjectName(_fromUtf8("addNoteButton"))
        self.addNoteButton.connect(self.addNoteButton, QtCore.SIGNAL("clicked()"), self.newNote)
        self.addNoteHorizontalLayout.addWidget(self.addNoteButton)
        self.addNoteLabel = QtGui.QLabel(self.horizontalLayoutWidget_4)
        self.addNoteLabel.setObjectName(_fromUtf8("addNoteLabel"))
        self.addNoteHorizontalLayout.addWidget(self.addNoteLabel)
        
        #przyciski do przesuwania notatek
        self.horizontalLayoutWidget_5 = QtGui.QWidget(dayWidget)
        self.horizontalLayoutWidget_5.setGeometry(QtCore.QRect(350, 480, 81, 31))
        self.horizontalLayoutWidget_5.setObjectName(_fromUtf8("horizontalLayoutWidget_5"))
        self.addNoteHorizontalLayout2 = QtGui.QHBoxLayout(self.horizontalLayoutWidget_5)
        self.addNoteHorizontalLayout2.setMargin(2)
        self.addNoteHorizontalLayout2.setObjectName(_fromUtf8("addNoteHorizontalLayout2"))
        self.nextNoteButton = QtGui.QPushButton(self.horizontalLayoutWidget_5)
        self.nextNoteButton.setMinimumSize(QtCore.QSize(15, 0))
        self.nextNoteButton.setMaximumSize(QtCore.QSize(27, 23))
        self.nextNoteButton.setObjectName(_fromUtf8("nextNoteButton"))
        self.nextNoteButton.connect(self.nextNoteButton, QtCore.SIGNAL("clicked()"), self.previousNote)
        self.addNoteHorizontalLayout2.addWidget(self.nextNoteButton)
        self.notesLabel = QtGui.QLabel(self.horizontalLayoutWidget_5)
        self.notesLabel.setObjectName(_fromUtf8("addNoteLabel"))
        self.addNoteHorizontalLayout2.addWidget(self.notesLabel)
        self.previousNoteButton = QtGui.QPushButton(self.horizontalLayoutWidget_5)
        self.previousNoteButton.setMinimumSize(QtCore.QSize(15, 0))
        self.previousNoteButton.setMaximumSize(QtCore.QSize(27, 23))
        self.previousNoteButton.setObjectName(_fromUtf8("previousNoteButton"))
        self.previousNoteButton.connect(self.previousNoteButton, QtCore.SIGNAL("clicked()"), self.nextNote)
        self.addNoteHorizontalLayout2.addWidget(self.previousNoteButton)


        self.retranslateUi(dayWidget)
        QtCore.QMetaObject.connectSlotsByName(dayWidget)

    def retranslateUi(self, dayWidget):
        dayWidget.setWindowTitle(QtGui.QApplication.translate("dayWidget", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.dataTextLabel.setText(QtGui.QApplication.translate("dayWidget", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt;\">Data: </span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.dataLabel.setText(self.date.toString("dd.MM.yyyy"))
        self.addNoteButton.setText(QtGui.QApplication.translate("dayWidget", "+", None, QtGui.QApplication.UnicodeUTF8))
        self.nextNoteButton.setText(QtGui.QApplication.translate("dayWidget", "<", None, QtGui.QApplication.UnicodeUTF8))
        self.previousNoteButton.setText(QtGui.QApplication.translate("dayWidget", ">", None, QtGui.QApplication.UnicodeUTF8))
        self.notesLabel.setText(QtGui.QApplication.translate("dayWidget", str(self.currentNote) + "/" + str(len(self.listOfNotes)), None, QtGui.QApplication.UnicodeUTF8))
        self.addNoteLabel.setText(QtGui.QApplication.translate("dayWidget", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">Dodaj nowy wpis</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))

